<%@ page language="java" contentType="text/html; charset=UTF-8"  pageEncoding="UTF-8"%>
<!DOCTYPE HTML>
<html>
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
	<title>商城物品管理</title>
	<%@ include file="/view/common/tags.jsp"%>
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta content="width=device-width, initial-scale=1" name="viewport" />
    <meta content="" name="description" />
    <meta content="" name="author" />
<body>
<section class="content">
 	<div class="row"> 
    	<div class="col-md-12">
	     	<div class="box">
	            <div class="box-body">
	               <div class="panel panel-default">
	                    <div class="panel-body" style="padding-bottom:5px;">
	                        <form class="form-horizontal" action="/pubgExchangeGoods/list" method="post" id="pubgExchangeGoodsForm">
	                            <div class="searchMenu">
	                                <div  class="mal10">
	                                    <%--<button type="button"  class="btn btn-primary btn-sm"  onclick="findData()"><span class='glyphicon glyphicon-search'></span>查&nbsp;询</button>--%>
	                                    <sk:button type="button"   rightKey="20170816152948" _class="btn btn-success btn-sm"  onclick="add('0')"><span  class='glyphicon glyphicon-search'></span>添&nbsp;加</sk:button>
	                                </div>
	                            </div>
	                        </form>
	                    </div>
	                </div>
	                <table class="table-scrollable table table-hover  table-bordered" id="pubgExchangeGoodsTable" data-striped=true>
	                    <thead>
	                        <tr>
	                            <th data-field="index" data-align="center" data-formatter="indexFormatter" data-sortable="false">序号</th>
	                            <th data-field="goodsName" data-align="center">物品名称</th>
	                            <th data-field="goodsPrice" data-align="center">物品价格</th>
								<th data-field="openFlag" data-align="center" data-formatter="openFlagFormatter" data-sortable="true">状态</th>
	                            <th data-field="optAccount" data-align="center">操作人</th>
	                            <th data-field="optTime" data-align="center" data-formatter="timeFormatter_point" >操作时间</th>
	                            <th data-field="optButton" data-align="center" data-sortable="false" data-formatter="buttonFormatter">操作</th> 
	                        </tr>
	                    </thead>
	                </table>
	            </div>
	        </div>
		</div>
	</div>
	<input type="hidden" id="msgg"  value="${msg}">
	<input type="hidden" id="code"  value="${code}">
</section>
   <%@ include file="/view/common/footer.jsp"%>
</body>
<script>
    var msgg = $("#msgg").val();
    var code = $("#code").val();
    $(function(){
        if( code== 1) {
            layer.msg(msgg);
        }
    })
    function openFlagFormatter(value, row) {
        var html = "";
        if (row.openFlag == 1) {
            html = "<span class='text-success'>启用 </span>&nbsp;&nbsp;&nbsp;&nbsp;";
            html += "<button id='btn_edit' type='button' onclick='_stop("+row.rowId+", "+row.openFlag+", \""+row.goodsName+"\");'    class='btn btn-default btn-sm '><span class='glyphicon glyphicon-stop'></span>停用</button>";
            return html;
        } else {
            html = "<span class='text-warning'>停用 </span>&nbsp;&nbsp;&nbsp;&nbsp;";
            html += "<button id='btn_edit' type='button' onclick='_stop("+row.rowId+", "+row.openFlag+", \""+row.goodsName+"\");'    class='btn btn-default btn-sm '><span class='glyphicon glyphicon-ok'></span>启用</button>";
            return html;
        }
    }

    //停用（启用）
    function _stop(rowId, openFlag, goodsName){
        var descStr = "【停用】<a style='color:red'>"+'"'+goodsName+'"'+'</a>';
        if (openFlag == 0) {
            descStr = "【启用】<a style='color:red'>"+'"'+goodsName+'"'+'</a>';
        }
        openFlag = Math.abs(Number(openFlag) - 1);
        layer.confirm('您确认'+descStr+'商城物品吗？', {
                btn: ['确认', '取消']
            },
            function(){
                if (rowId == null || rowId == "") {
                    layer.msg("id不能为空!");
                    return;
                }
                $.post(JSSYSMANAGERV1 + "/pubgExchangeGoods/updateOpenFlag?rowId="+rowId+"&openFlag="+openFlag,null,function(json){
                    if (json == 1) {
                        layer.msg(descStr+"成功", {icon: 1});
                        findData();
                    } else if(json == "-2"){
                        window.location.href= JSCTX;
                    } else {
                        layer.msg(descStr+"失败", {icon: 5});
                    }
                });
            },
            function(){
                return;
            });
    }

    //操作按钮
    function buttonFormatter(value, row,index) {
        var e = "<button id='btn_edit' type='button' onclick='add("+row.rowId+");'  class='btn btn-default btn-sm'><span class='glyphicon glyphicon-pencil'></span>修改</button>";
        return e;
    }

    //添加/修改
    function add(rowId){
        var titleBar = "添加商城物品";
        if (rowId != null && rowId > 0) {
            titleBar = "编辑商城物品";
		}
        layer.open({
            type: 2,
            title: titleBar,
            closeBtn: 1,
            shadeClose: true,
            area: ['500px', '500px'],
            content: JSSYSMANAGERV1 + '/pubgExchangeGoods/pubgExchangeGoodsEditer?rowId=' + rowId,
            btn: ["确 认","关 闭"],
            yes: function(index, layero){
                var iframeWin = window[layero.find('iframe')[0]['name']]; //得到iframe页的窗口对象，执行iframe页的方法：
                iframeWin.add();
            }
        });
    }

    $(function(){
        $("#pubgExchangeGoodsTable").bootstrapTable({
            url: JSSYSMANAGERV1 + "/pubgExchangeGoods/listPubgExchangeGoods.json",
            method:"get",
            pagination:true,
            sidePagination:"server",
            queryParams: function(params) {
                return $.extend({}, params, parseJson(decodeURIComponent($("#pubgExchangeGoodsForm").serialize())));
            }
        });
    })
    function findData(){
        $("#pubgExchangeGoodsTable").bootstrapTable("refresh",{} );
    }
</script>
</html>